package com.hspedu.exit_;

public class ThreadExit_ {
    public static void main(String[] args) throws InterruptedException {
        T t = new T();
        t.start();
        //如果希望主线程控制t1线程的退出或终止，希望Main线程可惜修改loop变量
        //让t退出run方法，从而终止 t1线程--> 通知方式
        Thread.sleep(10000);
        t.setLoop(false);
    }
}

class T extends Thread{
    private boolean loop=true;
    private int count=0;
    @Override
    public void run() {
        while(loop){
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("AThread  运行中..."+(++count));
        }
    }

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
}
